import http from './http'

const mediaApi = {

  /** /api/lecture */
  getMediaList ({ gid, page, ...params }) {
    let q = http.buildQuery(params)
    return http.get(`api/lecture?_format=json&group_id=${gid}&page=${page}&${q}`)
  },

  /** /api/lecture/:id */
  getMediaDetail (id) {
    return http.get(`api/lecture/${id}?_format=json`)
  },

  /** /api/lecture */
  postMedia (data) {
    return http.post('api/lecture', data)
  },

  /** /api/lecture/:id */
  patchMedia ({ id, ...data }) {
    return http.patch(`api/lecture/${id}`, data)
  },

  deleteMedia (id) {
    return http.delete(`api/lecture/${id}`)
  },

  /** /api/lecture/:id/unit/:uid */
  getMediaUnitDetail (id, delta) {
    return http.get(`api/lecture/${id}/unit/${delta}?_format=json`)
  },

  /** /api/lecture/:id/unit */
  postMediaUnit (id, data) {
    return http.post(`api/lecture/${id}/unit`, data)
  },

  /** /api/lecture/:id/unit/:delta */
  patchMediaUnit ({ id, delta, ...data }) {
    return http.patch(`api/lecture/${id}/unit/${delta}`, data)
  },

  deleteMediaUnit ({ id, delta }) {
    return http.delete(`api/lecture/${id}/unit/${delta}`)
  }
}

export default mediaApi
